<template>
  <div>
    <swiper class="swiper" :options="options">
      <swiper-slide :key="item.imgUrl" v-for="item in swiperData">
        <div>
          <a :href="item.url">
            <img :src="item.imgUrl" alt="轮播图" />
            <span class="swiper-label">{{ item.label }}</span>
          </a>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
import { Swiper, SwiperSlide } from "vue-awesome-swiper";

export default {
  name: "MySwiper",
  components: {
    Swiper,
    SwiperSlide
  },
  data() {
    return {
      options: {
        pagination: {
          el: ".swiper-pagination"
        },
        touchMoveStopPropagation: true,
        autoplay: {
          delay: 150000,
          disableOnInteraction: false
        },
        on: {
          touchStart(event) {
            // 阻止触摸冒泡
            event.stopPropagation();
          }
        },
        loop: true
      }
    };
  },
  props: {
    swiperData: {
      type: Array,
      default() {
        return [
          {
            label: "图片",
            url: "/",
            imgUrl:
              "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3807427310,283445384&fm=26&gp=0.jpg"
          }
        ];
      },
      validator(value) {
        value.forEach(e => {
          if (
            !Object.prototype.hasOwnProperty.call(e, "label") ||
            !Object.prototype.hasOwnProperty.call(e, "url") ||
            !Object.prototype.hasOwnProperty.call(e, "imgUrl")
          )
            return false;
        });
        return true;
      }
    }
  }
};
</script>

<style lang="stylus" scoped>
.swiper
  margin 5px
  border-radius 5px
  img
    display block
    width 100%
  .swiper-label
    float left
    position: absolute
    bottom: 3px
    color: white
    margin-left 10px
    font-weight bold
  .swiper-pagination
    width 20%
    right 0px
    left auto
    --swiper-pagination-color white
    >>> .swiper-pagination-bullet
      width 5px
      height 5px
      margin 0 3px
</style>
